<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>


<body>
    <div id="app">
        <child :num="n" @addnum="add"></child>
    </div>
</body>

<script>
    new Vue({
        el: "#app",
        data: {
            n: 100,
        },
        methods: {
            add(n) {
                this.n += n;
            }
        },
        components: {
            "child": {
                props: ["num"],
                template: `<div>子组件<h3>父组件的数据为{{num}}</h3><button @click="add">+</button></div>`,
                methods: {
                    add() {
                        this.$emit("addnum", 5);
                    }
                }
            },
        }
    })
</script>

</html>